package com.darren.befriend.views;

import android.content.Context;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.view.View.OnClickListener;

import com.darren.befriend.R;

public class UserSettingItemView extends RelativeLayout implements
		OnClickListener {

	private HelveticaLTStdLight mLeftTitle;
	private HelveticaLTStdRoman mRightTitle;
	private ImageView mCellDirect;
	private OnCellDirectListener mListener;

	public UserSettingItemView(Context context) {
		super(context);
		initView();
	}

	public UserSettingItemView(Context context, AttributeSet attrs) {
		super(context, attrs);
		initView();
	}

	/**
	 * init views
	 */
	private void initView() {
		LayoutInflater.from(getContext()).inflate(
				R.layout.layout_user_setting_item, this, true);
		mLeftTitle = (HelveticaLTStdLight) findViewById(R.id.setting_item_left);
		mRightTitle = (HelveticaLTStdRoman) findViewById(R.id.setting_item_right);
		mCellDirect = (ImageView) findViewById(R.id.setting_item_cell_direct);
		RelativeLayout itemLayout = (RelativeLayout) findViewById(R.id.setting_item);
		itemLayout.setOnClickListener(this);
	}

	public void setOnCellDirectListener(OnCellDirectListener listener) {
		mListener = listener;
	}

	/**
	 * get left title
	 * 
	 * @return
	 */
	public HelveticaLTStdLight getLeftTitle() {
		return mLeftTitle;
	}

	/**
	 * get right title
	 * 
	 * @return
	 */
	public HelveticaLTStdRoman getRightTitle() {
		return mRightTitle;
	}

	/**
	 * get cell direct
	 * 
	 * @return
	 */
	public ImageView getCellDirect() {
		return mCellDirect;
	}

	/**
	 * set left title
	 */
	public void setLeftTitle(String leftTitle) {
		if (mLeftTitle != null) {
			mLeftTitle.setText(leftTitle);
		}
	}

	/**
	 * set right title
	 */
	public void setRightTitle(String rightTitle) {
		if (mRightTitle != null) {
			mRightTitle.setText(rightTitle);
		}
	}

	/**
	 * set show/hide right title
	 */
	public void setRightTitleVisibility(boolean value) {
		if (mCellDirect != null) {
			if (value == true) {
				mCellDirect.setVisibility(View.VISIBLE);
			} else {
				mCellDirect.setVisibility(View.INVISIBLE);
			}
		}
	}

	@Override
	public void onClick(View v) {
		int id = v.getId();
		switch (id) {
		case R.id.setting_item:
			if (mListener != null) {
				mListener.onCellClick();
			}
			break;

		default:
			break;
		}
	}

	public interface OnCellDirectListener {
		public void onCellClick();
	}
}
